<?php
// +------------------------------------------------------------------------------	
//	@desc adminController.php
//  @date Wed Aug 19 CST 2009
//  @author Fly Jin <flysharping@gamil.com>
// +------------------------------------------------------------------------------
class adminController extends Controller{

	//Request Login
	function logining(){
		if (isset($_POST)) {
			if (!empty($_POST['username'])&&!empty($_POST['password'])) {
				$AdminUser=loadModel('AdminUser');
				$isLogin=$AdminUser->login($_POST['username'],$_POST['password']);
				if ($isLogin) {
					redirect("/admin");
				}else {
					redirect("/admin/login");
				}
			}else{
				redirect_url('/admin/login','请输入用户名密码！');
			}
		}
	}
		
	//Request Logout
	function logout(){
		$_SESSION = array();
		session_destroy();
		redirect("/admin/login");
	}
	
	function isLogin() {
		if(!empty($_SESSION['username']))
			return 1;	
		else
			return 0;
	}

	function addCat(){
		if (!($this->isLogin())) {
			redirect("/admin/login");
		}
		$cate=new Cate();
		$cate->getTree();
		$attrArray['class'] = "text-box";
		//$attrArray['disabled'] = "true";
		$parentNode = $cate->buildSelect("parentNode", null, $attrArray);
		$varList = array(
							"title"			=> "文章分类添加",
							"parentNode"	=> $parentNode,
							"absPath"		=> "",
							"buttonValue"	=> "添 加",
							"catTitle"		=> "",
							"description"	=> "",
							//"imgName"		=> GALLERY_PATH . "no_image.gif"
						);
		$this->assign['varList']=$varList;
		//$this->tpl['queryTime']=$db->getQueryTimes();
		//$this->tpl['executeTime']=$timer->getExecuteTime();
	}
	
	function listCat(){
		if(empty($_SESSION['username'])){
			redirect("/admin/login");
		}
		$cate=new Cate();
		$condition['absPath'] = $_GET['absPath'];
		$tmpList = $cate->listCat($condition);
		$catTree = $cate->parseTree();
		$this->assign['title']= "文章类别管理";
		if($catTree) {
			$this->assign['catList']=$catTree;
			$this->assign['noChildClass']="not-display";
		}else{
			$this->assign['noChildClass']="light-row";
		}
	}
	
	function addArticle(){
		require_once(PATH_LIB.'FCKeditor'.DS.'fckeditor.php');
		//定义一个函数用于调用FCK
		$editor = new FCKeditor('content') ;
		$editor->BasePath   = "/Lib/FCKeditor/";//指定编辑器路径
		$editor->ToolbarSet = "Default";//编辑器工具栏有Basic（基本工具）,Default（所有工具）选择
		$editor->Width      = "100%";
		$editor->Height     = "320";
		$editor->Value      = '';
		$editor->Config['AutoDetectLanguage'] = true ;
		$editor->Config['DefaultLanguage']  = 'zh' ;//语言
		$FCKeditor = $editor->CreateHtml();
		$this->assign['editor']= $FCKeditor;//指定区域

		$this->display='admin/article.htm';
	}
	

	function editor($input_name=null, $input_value=null){
		require(PATH_LIB.'FCKeditor'.DS.'fckeditor.php');
		$editor = new FCKeditor($input_name) ;
		$editor->BasePath   = "/Lib/FCKeditor/";//指定编辑器路径
		
		$editor->ToolbarSet = "Default";//编辑器工具栏有Basic（基本工具）,Default（所有工具）选择
		$editor->Width      = "100%";
		$editor->Height     = "320";
		$editor->Value      = $input_value;
		$editor->Config['AutoDetectLanguage'] = true ;
		$editor->Config['DefaultLanguage']  = 'zh' ;//语言
		pr($editor);
		return $FCKeditor = $editor->CreateHtml();
	}
	//Display Tpl
	function login(){
		$this->display='admin/login.htm';
	}
	function top(){
		$this->display='admin/top.htm';
	}
	
	function menu(){
		$this->display='admin/menu.htm';
	}
	function center(){
		$this->display='admin/center.htm';
	}
	function buttom(){
		$this->display='admin/buttom.htm';
	}
	
	function main(){
		$this->display='admin/main.htm';
	}
	
	function setpwd(){
		$this->display='admin/setpwd.htm';
	}
	
	//After logining Display Index Tpl	
	function index(){
		$AdminUser=loadModel('AdminUser');
		$isLogin=$AdminUser->isLogin();
		if ($isLogin) {
			echo'
				<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
				<html xmlns="http://www.w3.org/1999/xhtml">
				<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<title>Administrator for fsdr.Cn </title>
				</head>
				<frameset rows="127,*,11" frameborder="no" border="0" framespacing="0">
					<frame src="/admin/top" 		name="topFrame" 	scrolling="No" 	noresize="noresize" id="topFrame" />
					<frame src="/admin/center" 	name="mainFrame" 	id="mainFrame" />
					<frame src="/admin/buttom" 	ame="bottomFrame" 	scrolling="No"	noresize="noresize" id="bottomFrame" />
				</frameset>
				<noframes>
				<body>
				</body>
				</noframes>
				</html>
				';
		}else {
			redirect("/admin/login");
		}
	}
	
}
?>